<%@ page language="java"
	import="java.util.*,com.wit.po.Company,com.wit.po.Power,com.wit.po.Subcompany,com.wit.po.Department,com.wit.po.Employee,com.wit.service.impl.DLcompanyserviceImp,com.wit.service.impl.EmployeeserviceImp,com.wit.service.impl.EPowerserviceImp"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
	DLcompanyserviceImp dlc = new DLcompanyserviceImp();
	List list = dlc.CompanyList();
	Company company = (Company) list.get(0);
%>
<%
    EmployeeserviceImp empser=new EmployeeserviceImp(); 
%>
<%
   EPowerserviceImp powerser=new EPowerserviceImp();
   List<Power> powerList=powerser.PowerList(); 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>组织管理</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link href="<%=basePath%>/style/main.css" rel="stylesheet"
			type="text/css" />
		<link type="text/css" rel="stylesheet"
			href="<%=basePath%>/style/style.css" />
		<style>
body#bodyTree {
	margin: 8px;
	font-size: 12px;
	color: #000;
	line-height: 22px;
}

body#bodyTree a {
	color: #000;
	text-decoration: none;
}

body#bodyTree a:hover {
	color: #3366CC;
	padding: 2px 0px 0px 0px;
}

#bodyTree ul {
	margin: 0;
	padding: 0;
	list-style: none;
	background: url(<%=basePath%>/images/tree/ullist.gif) repeat-y;
}

#bodyTree ul li {
	list-style: none;
}

#bodyTree .treeview li {
	background: transparent url(<%=basePath%>/images/tree/list.gif)
		no-repeat left center;
	padding-left: 15px; /*tree list*/
}

#bodyTree .treeview li.submenu {
	background: transparent url(<%=basePath%>/images/tree/closed.gif)
		no-repeat left 0px; /*4 sub menu*/
}

#bodyTree .treeview li.closefolder {
	background: transparent url(<%=basePath%>/images/tree/closed.gif)
		no-repeat left 0px; /*closefolder style*/
}

#bodyTree .treeview li.openfolder {
	background: transparent url(<%=basePath%>/images/tree/open.gif)
		no-repeat left 0px;
	/*openfolder style*/
}

#bodyTree .treeview li.submenu ul {
	display: none;
}

#bodyTree ul li a.cur {
	font-weight: bold;
	color: #3366CC;
	padding: 2px 2px 0px 2px; /*the current style*/
}

#bodyTree .treeview .submenu i {
	width: 12px;
	height: 12px;
	font-style: normal;
	font-size: 10px;
	margin-left: -15px;
	margin-top: 5px;
	float: left;
	display: inline;
	background: url(<%=basePath%>/images/tree/transparent.gif) no-repeat
		center;
	cursor: pointer;
}

#cmsTree {
	float: left;
	width: 15%;
}

#rightDiv {
     border:1px solid #5BA8DE;
     width:70%;
}

#Containner {	
}
	.mydiv input {
		width: 40px;
		font-size: 15pt;
		border: solid 1px #7F9DB9;
		font-size: 15px;	
       }
	.mydiv{
	background-color: #F1F6FF;
	}
	.myText{
	width: 300px;
	}
	.mydiv legend{
	font-size: 20px;	
	}
</style>
		<script type="text/javascript"
			src="<%=basePath%>/images/tree/simpletreemenu.js">
</script>
		<script type="text/javascript" src="<%=basePath%>/js/jquery-1.3.1.js">
</script>
<script type="text/javascript">
    //var employeeId;
    //var parameter = {employeeId :num}; 
   // function addEmployee()
     //  window.location.href("newEmployee.jsp?departmentId="+departmentId);
     $(document).ready(function(){
     $("#CheckAll").click(function(){
      $("#CheckNone").attr("checked",false);
     $("input:checkbox[name=urlname]").each(function(){
     $(this).attr("checked","checked");
     });
     });
     
      $("#CheckNone").click(function(){
      $("#CheckAll").attr("checked",false);
     $("input:checkbox[name=urlname]").each(function(){
     $(this).attr("checked",false);
     });
     });
     
       $("#newCheckAll").click(function(){
      $("#newCheckNone").attr("checked",false);
     $("input:checkbox[name=urlname]").each(function(){
     $(this).attr("checked","checked");
     });
     });
     
      $("#newCheckNone").click(function(){
      $("#newCheckAll").attr("checked",false);
     $("input:checkbox[name=urlname]").each(function(){
     $(this).attr("checked",false);
     });
     });
     });
     function employee(num)
     {
      document.getElementById("bassicDiv").style.display="";
	  document.getElementById("newbassicDiv").style.display="none";
       $("input:checkbox[name=urlname]").each(function(){
		   
		     $(this).attr("checked",false);
		     }); 
         $("#InvisibleValue").val(num);
         $("#newInvisibleValue").val(num);
        var parameter={InvisibleValue:num};
        $.ajax({
		type : "post",
		dataType : "json",
		data : parameter,
		url : "CheckPowerAction", 
		success:function(data){ 
		if(data.length==0)
		{
	      document.getElementById("bassicDiv").style.display="none";
	      document.getElementById("newbassicDiv").style.display="";
		   alert('该用户没有赋予任何权限');
		
		}
		else{
		  $.each(data,function(commentIndex, comment) {
		  $("input:checkbox[name=urlname]").each(function(){
		   if(comment.powerId==$(this).val())
		     $(this).attr("checked",true);
		     });          
		    });
		     }
		}
		});
     }	
      
</script>
	</head>
		<body id="bodyTree">
			<div id="Containner">
				<div id="cmsTree">
					<ul id="treemenu3" class="treeview">
						<li>
							<strong>组织架构</strong>
							<a href="javascript:ddtreemenu.flatten('treemenu3', 'expand')"><strong>展开</strong>
							</a>
							<a href="javascript:ddtreemenu.flatten('treemenu3', 'contact')"><strong>收缩</strong>
							</a>
						</li>
						<li>
							<i></i><span><%=company.getCompanynameC()%></span>
							<%
							    List<Department> dlist=dlc.ReturncompanyD(company.getCompanyNum()); 
							    if(dlist.size()>0)
							    {
							%>
							<ul>
							        <%
							        for(int i=0;i<dlist.size();i++)
							        { 
							        %>
							        <li><i></i><%=dlist.get(i).getDepartNameC() %></li>
							        <%
							         List<Employee> listA1=empser.EmployeeList(dlist.get(i).getDepartmentId());
							         if(listA1.size()>0)
							         { 
							        %>
                                    <ul>							   
							        <%
							        for(int a1=0;a1<listA1.size();a1++)
							        { 
							        %>
							        <li> <span onclick="employee('<%=listA1.get(a1).getEmployeeId()%>')"><%=listA1.get(a1).getEmployeeNameC()  %></span></li>
							        <%
							        } 
							        %>
							      </ul>
							        <%
							        } 
							        %>
							        
							        <%
							        }
							        %>
							
							<%
							   }
							 %>
							<%
								List<Subcompany> flist = dlc.FirstLevel();
								if (flist.size() > 0) {
							%>
							
								<%
									for (int i = 0; i < flist.size(); i++) {
											//第一层代理
											Subcompany sub = flist.get(i);
								%>

								<li>
									<i></i><span><%=sub.getSshortName()%></span>
									<%
									   List<Department> alist=dlc.ReturnSubcompanyD(sub.getSubcommpanyId()); 
							           if(alist.size()>0)
							          {
									%>
									   <ul>
									    <%
									    for(int j=0;j<alist.size();j++)
									    {
									    %>
									    <li><i></i><%=alist.get(j).getDepartNameC() %></li>
									    <%
									    List<Employee> listA2=empser.EmployeeList(alist.get(j).getDepartmentId());
									    if(listA2.size()>0)
									    { 
									    %>
									    <ul>
									    <%
									    for(int a2=0;a2<listA2.size();a2++)
									    { 
									    %>
									    <li> <span onclick="employee('<%=listA2.get(a2).getEmployeeId() %>')"><%=listA2.get(a2).getEmployeeNameC() %></span></li>
									    <%
									    } 
									    %>
									    </ul>
									    <%
									    } 
									    %>
									    <%
									    } 
									    %>
									   </ul>
									<% 
									   }
									%>
									<%
										int size = sub.getSubcompanies().size();
												if (size > 0) {
													//第二层
									%>
									<ul>
										<%
											Iterator it = sub.getSubcompanies().iterator();
														while (it.hasNext()) {
															Subcompany selevel = (Subcompany) it.next();
										%>

										<li>
											<i></i><span><%=selevel.getSshortName()%></span>
											<%
										  	 List<Department> blist=dlc.ReturnSubcompanyD(selevel.getSubcommpanyId()); 
								          	 if(blist.size()>0)
								          	{
										   %>
										   <ul>
										    <%
										    for(int k=0;k<blist.size();k++)
										    {
										    %>
										    <li><i></i><%=blist.get(k).getDepartNameC() %></li>
										    <%
										    List<Employee> listA3=empser.EmployeeList(blist.get(k).getDepartmentId());
										    if(listA3.size()>0)
										    { 
										    %>
										    <ul>
										    <%
										    for(int a3=0;a3<listA3.size();a3++) 
										    {
										    %>
										    <li><span onclick="employee('<%=listA3.get(a3).getEmployeeId() %>')"><%=listA3.get(a3).getEmployeeNameC() %></span></li>
										    <%
										    } 
										    %>
										    </ul>
										    <%
										    } 
										    %>
										    <%
										    } 
										    %>
										   </ul>
											<% 
										  	 }
											%>
											<%
												int three = selevel.getSubcompanies().size();
																if (three > 0) {
																	//第三层
											%>
											<ul>
												<%
													Iterator threeit = selevel.getSubcompanies()
																				.iterator();
																		while (threeit.hasNext()) {
																			Subcompany threelevelc = (Subcompany) threeit
																					.next();
												%>

												<li>
													<i></i><span><%=threelevelc.getSshortName()%></span>
													<%
												  	 List<Department> clist=dlc.ReturnSubcompanyD(threelevelc.getSubcommpanyId()); 
										          	 if(clist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<clist.size();k++)
												    {
												    %>
												    <li><i></i><%=clist.get(k).getDepartNameC() %></li>
												    <%
												    List<Employee> listA4=empser.EmployeeList(clist.get(k).getDepartmentId());
												    if(listA4.size()>0)
												    { 
												    %>
												    <ul>
												    <% 
												    for(int a4=0;a4<listA4.size();a4++)
												    {
												    %>
												    <li><span onclick="employee('<%=listA4.get(a4).getEmployeeId() %>')"><%=listA4.get(a4).getEmployeeNameC() %></span></li>
												    <%
												    } 
												    %>
												    </ul>
												    <%
												    } 
												    %>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
													<%
														int four = threelevelc.getSubcompanies()
																						.size();
																				if (four > 0) {
																					//第四层
													%>
													<ul>
														<%
															Iterator fourlevel = threelevelc
																								.getSubcompanies().iterator();
																						while (fourlevel.hasNext()) {
																							Subcompany fourlevelc = (Subcompany) fourlevel
																									.next();
														%>

														<li>
															<i></i><span><%=fourlevelc
													.getSshortName()%></span>
													<%
												  	 List<Department> elist=dlc.ReturnSubcompanyD(fourlevelc.getSubcommpanyId()); 
										          	 if(elist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<elist.size();k++)
												    {
												    %>
												    <li><i></i><%=elist.get(k).getDepartNameC() %></li>
												    <%
												    List<Employee> listA5=empser.EmployeeList(elist.get(k).getDepartmentId());
												    if(listA5.size()>0)
												    { 
												    %>
												    <ul>
												    <%
												    for(int a5=0;a5<listA5.size();a5++) 
												    {
												    %>
												    <li><span onclick="employee('<%=listA5.get(a5).getEmployeeId()%>')"><%=listA5.get(a5).getEmployeeNameC() %></span></li>
												    <%
												    } 
												    %>
												    </ul>
												    <%
												    } 
												    %>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
															<%
																int five = fourlevelc
																										.getSubcompanies().size();
																								if (five > 0) {
															%>
															<ul>
																<%
																	Iterator fivelevel = fourlevelc
																												.getSubcompanies()
																												.iterator();

																										while (fivelevel.hasNext()) {
																											Subcompany fivelevelc = (Subcompany) fivelevel
																													.next();
																%>
																<li><span><%=fivelevelc
															.getSshortName()%></span>
															<%
												  	 List<Department> klist=dlc.ReturnSubcompanyD(fivelevelc.getSubcommpanyId()); 
										          	 if(klist.size()>0)
										          	{
												   %>
												   <ul>
												    <%
												    for(int k=0;k<klist.size();k++)
												    {
												    %>
												    <li><i></i><%=klist.get(k).getDepartNameC() %></li>
												    <%
												    List<Employee> listA6=empser.EmployeeList(klist.get(k).getDepartmentId());
												    if(listA6.size()>0)
												    { 
												    %>
												    <ul>
												    <%
												      for(int a6=0;a6<listA6.size();a6++)
												      { 
												    %>
												    <li><span onclick="employee('<%=listA6.get(a6).getEmployeeId() %>')"><%=listA6.get(a6).getEmployeeNameC() %></span></li>
												    <%
												      } 
												    %>
												    </ul>
												    <%
												    } 
												    %>
												    <%
												    } 
												    %>
												   </ul>
													<% 
												  	 }
													%>
															</li>
																<%
																	}
																%>
															</ul>
															<%
																}
															%>
														</li>
												</li>
												<%
													}
												%>
											</ul>
											<%
												}
											%>
										</li>
										<%
											}
										%>
									</ul>
									<%
										}
									%>
								</li>
								<%
									}
								%>
							</ul>
							<%
								}
							%>
						</li>
						<%
							//到这里第一层结束
								}
						%>
					</ul>
					<%
						}
					%>
					
					
				</div>
				<div id="rightDiv" style="position:absolute">
				<div class="mydiv" id="bassicDiv">
    <form id="EmployeeMessage" action="MendEPowerAction" method="post">
    <fieldset> 
   <div class="FuckTittle"><span class="title">基本资料</span></div>
      <p>&nbsp;</p>
      <div class="table4">
    <input type="hidden" id="InvisibleValue" name="InvisibleValue"/>
    <p>
       <input type="checkbox" id="CheckAll"/>全部选择   &nbsp;&nbsp;&nbsp;<input type="checkbox" id="CheckNone"/>全不选择
    </p><p>&nbsp;</p>
    <%
      for(int ln=0;ln<powerList.size();ln++)
      {
        if(ln%2==0)
        {   
    %>
    <p><input type="checkbox" id="urlname" name="urlname" value="<%=powerList.get(ln).getPowerId()%>"/><span class="myText"><%=powerList.get(ln).getPowerName() %></span>
        <%
        } 
        if(ln%2==1)
        {
        %>
        <input type="checkbox" id="urlname" name="urlname" value="<%=powerList.get(ln).getPowerId()%>"/><span class="myText"><%=powerList.get(ln).getPowerName() %></span></p><p>&nbsp;</p>
    <%
        }
      } 
    %>
    <p>&nbsp;</p>
      <p >
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="input" type="submit"  value="修改"  class="btn_1" />&nbsp;&nbsp; <input name="input" type="reset"  value="取消"  class="btn_1"/>
    </p>
    </div>
    </fieldset>
   </form>	
   </div>
   
   
   <div class="mydiv" id="newbassicDiv" style="display:none">
    <form id="EmployeeMessage" action="AddEPowerAction" method="post">
    <fieldset> 
    <div class="FuckTittle"><span class="title">权限列表</span></div>
      <p>&nbsp;</p>
      <div class="table4">
    <p>&nbsp;</p>
    <input type="hidden" id="newInvisibleValue" name="InvisibleValue"/>
    <p>
       <input type="checkbox" id="newCheckAll"/>全部选择   &nbsp;&nbsp;&nbsp;<input type="checkbox" id="newCheckNone"/>全不选择
    </p><p>&nbsp;</p>
    <%
      for(int ln=0;ln<powerList.size();ln++)
      {
        if(ln%2==0)
        {   
    %>
    <p><input type="checkbox" id="urlname" name="urlname" value="<%=powerList.get(ln).getPowerId()%>"/><span class="myText"><%=powerList.get(ln).getPowerName() %></span>
        <%
        } 
        if(ln%2==1)
        {
        %>
        <input type="checkbox" id="urlname" name="urlname" value="<%=powerList.get(ln).getPowerId()%>"/><span class="myText"><%=powerList.get(ln).getPowerName() %></span></p><p>&nbsp;</p>
    <%
        }
      } 
    %>
    <p>&nbsp;</p>
      <p >
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="input" type="submit"  value="保存"  class="btn_1" />&nbsp;&nbsp; <input name="input" type="reset"  value="取消"  class="btn_1"/>
    </p></div>
    </fieldset>
   </form>	
   </div>
</div>
</div>
			<script type="text/javascript">
              ddtreemenu.createTree("treemenu3", true);
            </script>
		</body>
</html>
